using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SystemFramework.Util;

namespace TF.Access {
	public partial class TF_Blog {

        /// <summary>
        /// Deletes a record from the TF_Blog table by its primary key.
        /// </summary>
        public void DeleteCasecade()
        {
            SqlClientUtility.ExecuteNonQuery("TF_BlogDeleteCasecade", iD);
        }

        /// <summary>
        /// Selects all records from the TF_Blog table.
        /// </summary>
        public static TF_Blog SelectBlogByOwnerIdAndBlogId(int uid, int blogId, out int preBlogId, out int nextBlogId, out string blogTitle)
        {
            TF_Blog ret = null;
            preBlogId = 0;
            nextBlogId = 0;
            blogTitle = string.Empty;
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_BlogSelectByOwnerIdAndBlogId", uid, blogId))
            {
                while (dataReader.Read())
                {
                    ret = MakeTF_Blog(dataReader);
                }

                if (dataReader.NextResult())
                {
                    if (dataReader.Read())
                    {
                        preBlogId = ConvertHelper.GetInt(dataReader[0], 0);
                    }
                }

                if (dataReader.NextResult())
                {
                    if (dataReader.Read())
                    {
                        nextBlogId = ConvertHelper.GetInt(dataReader[0], 0);
                        blogTitle = ConvertHelper.GetString(dataReader[1], string.Empty);
                    }
                }

            }

            return ret;
        }

        /// <summary>
        /// Selects all records from the TF_Blog table.
        /// </summary>
        public static List<TF_Blog> SelectBlogByOwnerId(int uid, int pageSize, int pageIndex, out int count)
        {
            count = 0;
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("TF_BlogSelectByOwnerId", uid, pageSize, pageIndex))
            {
                List<TF_Blog> tF_BlogList = new List<TF_Blog>();
                while (dataReader.Read())
                {
                    TF_Blog tF_Blog = MakeTF_Blog(dataReader);
                    tF_BlogList.Add(tF_Blog);
                }

                if (dataReader.NextResult())
                {
                    if (dataReader.Read())
                    {
                        count = ConvertHelper.GetInt(dataReader[0], 0);
                    }
                }
                return tF_BlogList;
            }
        }
	}
}
